<%@page import="com.sinba.common.system.dto.RuleDTO"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="com.sinba.common.system.service.IRuleService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">  
<%
request.setAttribute("errorInfo",request.getParameter("error"));
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
IRuleService ruleService = (IRuleService)ac.getBean("ruleService");
RuleDTO ruleDTO = ruleService.findRuleInfo();
request.setAttribute("ruleDTO",ruleDTO);
request.setAttribute("errorInfo",request.getParameter("error"));
request.setAttribute("loginName",request.getParameter("loginName"));
request.setAttribute("registerLocation",request.getParameter("registerLocation"));
request.setAttribute("contactNo",request.getParameter("contactNo"));
request.setAttribute("recommendUser",request.getParameter("recommendUser"));
request.setAttribute("declarationCenters",request.getParameter("declarationCenters"));
%>

<%@ include file="../language.jsp" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title><fmt:message key="i18n.login" />-<fmt:message key="i18n.title"/></title>
<link rel="shortcut icon" href="../images/favicon.png" />
<link href="../styles/artDialog-default.css" rel="stylesheet" />
	<!-- JQUERY -->
<script type="text/javascript" src="../scripts/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<script type="text/javascript" src="../scripts/jquery.artDialog.min.js"></script>
<script type="text/javascript" src="../scripts/user/common.js"></script>
<script type="text/javascript" src="../scripts/user/login.js"></script>
<script type="text/javascript" src="../scripts/user/reguser.js"></script>
<<!-- STYLESHEETS --><!--[if lt IE 9]><script src="${basePath}CloudFrame/js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
	<link rel="stylesheet" type="text/css" href="${basePath}CloudFrame/css/cloud-admin.css" >
	
	<link href="${basePath}CloudFrame/font-awesome/css/font-awesome.min.css" rel="stylesheet">
	<!-- DATE RANGE PICKER -->
	<link rel="stylesheet" type="text/css" href="${basePath}CloudFrame/js/bootstrap-daterangepicker/daterangepicker-bs3.css" />
	<!-- UNIFORM -->
	<link rel="stylesheet" type="text/css" href="${basePath}CloudFrame/js/uniform/css/uniform.default.min.css" />
	<!-- ANIMATE -->
	<link rel="stylesheet" type="text/css" href="${basePath}CloudFrame/css/animatecss/animate.min.css" />
	<!-- FONTS -->
	<!-- <link href='http://fonts.useso.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'> -->
	<script type="text/javascript">
var winHeight = $(window).height(); 
function readUserAgreement(){
	$.dialog({
	    title: '<fmt:message key="i18n.lookAgreement"/>',lock: true,
	    width: 620, height: (winHeight * 0.6),//仅能为数字
	    content: $('#userAgreement').html(),
	    okValue: '<fmt:message key="i18n.consentAgreement"/>', ok: function () {
	    	$("#register_form").submit();
	    },
		cancelValue: ' <fmt:message key="i18n.cancel"/> ', cancel: function () {
	    }
	});
}
$(function(){

	$("#getRegisterCode").click(function(){
		window.location.href="lottery.jsp"
	});
	$("#register_form_submit").click(function(){
		/* alert($("#registerPwdCheck").val()); alert($("#registerPwd").val());return; */
		if( $("#registerAccount").val() === ""){
			alert( "登入账号不允许为空!" ); 
			$("#registerAccount").focus();
			return;
		}
		
		var re =new RegExp("^[A-Za-z0-9]{6,10}$");
		if (!re.test($('#registerAccount').val())){
			alert("登入账号最少6位，只能由英文和数字组成！");
			$('#registerAccount').focus();
			return;
		}
		
		if( $("#registerPwd").val() === ""){
			alert( "登陆密码不允许为空!" ); $("#registerPwd").focus();return;
		}
		/* if( $("#registerPwdCheck").val() === ""){
			alert( "Confirm Password does not allow null(确认密码不允许为空)!" ); $("#registerPwdCheck").focus();return;
		} */
		if( $("#registerPwdCheck").val() !== $("#registerPwd").val()){
			alert( "两次密码不一致，请检查输入!" ); $("#registerPwdCheck").focus();return;
		}
		
		if( $("#registerMobile").val() === ""){
			alert( "手机号码不允许为空!" ); $("#registerMobile").focus();return;
		}
		
		if( !checkMobile($("#registerMobile").val())){
			alert( "手机号码不正确!" ); $("#registerMobile").focus();return;
		}
		
		if( $("#registerAuthCode").val() === ""){
			alert( "请输入手机收到的验证码!" ); $("#registerAuthCode").focus();return;
		}
		readUserAgreement();
		//$("#register_form").submit();
	});
	var resultStr = "${resultStr}";var loginName = "${resultStrLoginName}";
	if ( loginName !== "" && resultStr !== ""){
		//alert( resultStr );
		$("#registerAccount").val( loginName );
		if("SUCCESSFUL" === resultStr){
			alert( "注册成功,系统将自动跳转到登录页面" );
			window.location.href = "login.jsp"
		}else if("ACTIVATION_CODE_ERROR" === resultStr){
			alert( "验证码错误" );
		}else if("LOGINNAME_ALREADY_REGISTERED" === resultStr){
			alert( "此账号已经被注册" );
		}else if("ERROR_PARAM" === resultStr){
			alert( "输入参数错误，请检查输入" );
		}else if("REGISTER_CODE_INVALID" === resultStr){
			alert( "注册码无效" );
		}else{
			alert( resultStr );
		}
	}else{
		//alert(2);
	}
});
</script>
</head>
<body class="login">	
	<!-- PAGE -->
	<section id="page">
			<!-- HEADER -->
			<header>
				<!-- NAV-BAR -->
				<div class="container">
					<!-- <div class="row">
						<div class="col-md-4 col-md-offset-4">
							<div id="logo">
								<img src="img/logo.png">
							</div>
						</div>
					</div> -->
				</div>
				<!--/NAV-BAR -->
			</header>
			<!--/HEADER -->
			<!-- LOGIN -->
			<section id="login" class="visible">
				<div class="container">
					<div class="row">
						<div class="col-md-4 col-md-offset-4">
							<div class="login-box-plain" style="background-color:#FFFACD;">
									<div id="logo" >
										<img src="img/logo.png" style="height: 100px;">
									</div>
								<div class="divide-40"></div>
								<form role="form" action="registerUser!login.action" method="post" id="my-form">
								  <div class="form-group">
									<label >登入账号</label>
									<i class="fa fa-user"></i>
									<input id="loginName" class="form-control" name="registerUserDTO.loginName" type="text" placeholder="请输入登入账号"  >
								  </div>
								  <div class="form-group"> 
									<label for="exampleInputPassword1">登入密码</label>
									<i class="fa fa-lock"></i>
									<input id="password" class="form-control" name="registerUserDTO.password1" type="password" placeholder="请输入登入密码">
								  </div>
								  <div class="form-group"> 
									<div class="row">
										<div class="col-xs-8">
										<label >验证码</label>
										</div>
									</div>
									<div class="row">
										<div class="col-xs-8">
											<i class="fa fa-lock"></i>
											<input class="form-control" name="code" id="userLogin_validCode" type="text" placeholder="填写验证码" >
										</div>
										<div class="col-xs-4">
											<a href="javascript:refreshCheckCode('login_codeImg');" >
					           					<img id="login_codeImg" border=0 src="randomCode" />
					         				</a>
					         			</div>
				         			</div>
								  </div>
								  <div class="form-actions" style="background-color:#FFFACD;">
									<button onclick="userLogin('yes')" class="btn btn-danger" type="button" >登    入</button>
								  </div>
								</form>
								<!-- SOCIAL LOGIN -->
								<div class="divide-20"></div>
								<c:if test="${not empty errorInfo }">
								<div class="center" style="color:red;font-size:16px;">
									<c:if test="${errorInfo eq 'LoginNameOrPasswordError' }">会员账号或密码不正确,请重新登入!</c:if>
						     		<c:if test="${errorInfo eq 'NotActivation' }">会员账号未激活，请联系客服进行激活!</c:if>
						     		<c:if test="${errorInfo eq 'LoginNameAlreadyLock' }">会员账号已被冻结，请联系客服!</c:if>
								</div>
								</c:if>
								<div class="divide-20"></div>
								<!-- /SOCIAL LOGIN -->
								<div class="login-helpers">
									<a href="#" onclick="swapScreen('forgot');return false;">忘记密码？</a> <br>
									<a href="#" onclick="swapScreen('register');return false;">注 册</a>
								</div>
							</div>
						</div>
					</div>
				</div>
			</section>
			<!--/LOGIN -->
			<!-- REGISTER -->
			<section id="register">
				<div class="container">
					<div class="row">
						<div class="col-md-4 col-md-offset-4">
							<div class="login-box-plain" style="background-color:#FFFACD;">
								<h2 class="bigintro"><fmt:message key="i18n.newUserReg" /></h2>
								<div class="divide-40"></div>
								<form role="form" action="registerUser!regiserUser.action" method="post" id="register_form">
								<input type="hidden" name="registerUserDTO.recommendUser" value="${recommendUser }"/>
						        <input type="hidden" name="registerUserDTO.contactNo" value="${contactNo }"/>
						        <input type="hidden" name="registerUserDTO.registerLocation" value="${registerLocation}"/>
								  <div class="form-group">
									<label for="exampleInputUsername"><i>*</i>登入账号：</label>
									<i class="fa fa-user"></i>
									<input type="text" class="form-control" name="registerUserDTO.loginName" id="registerAccount" onBlur="checkLoginNameIsExistAndShow('registerAccount','showResult')" placeholder="请输入您的账号" />
									<span style="color: red;" id="showResult"></span>
								  </div>
								  <div class="form-group"> 
									<label for="exampleInputPassword1"><i>*</i><fmt:message key="i18n.loginPassword" />：</label>
									<i class="fa fa-lock"></i>
									<input type="password" class="form-control" name="registerUserDTO.password1" id="registerPwd" placeholder="<fmt:message key="i18n.regInputPwd" />" >
								  </div>
								  <div class="form-group"> 
									<label for="exampleInputPassword1"><i>*</i><fmt:message key="i18n.cofimPassword" />：</label>
									<i class="fa fa-check-square-o"></i>
									<input type="password" class="form-control" placeholder="<fmt:message key="i18n.regInputRepwd" />" id="registerPwdCheck"  >
								  </div>
								  <div class="form-group"> 
									<label for="exampleInputPassword1"><i>*</i>手机号码：</label>
									<i class="fa fa-lock"></i>
									<input class="form-control" type="text" name="registerUserDTO.mobile" id="registerMobile" placeholder="请输入您的手机号码" >
								  </div>
								  <div class="form-group"> 
									<div class="row">
										<div class="col-xs-8">
										<label ><i>*</i><fmt:message key="i18n.mobileCode" />：</label>
										</div>
									</div>
									<div class="row">
										<div class="col-xs-7">
											<i class="fa fa-lock"></i>
											<input class="form-control" type="text" id="registerAuthCode" name="registerUserDTO.authCode" placeholder="<fmt:message key="i18n.regInputVerificationCode" />" >
										</div>
										<div class="col-xs-5">
											<button class="form-control" id="getRegisterAuthCode" onclick="getVerificationCode('Mobile','Register','#registerMobile','#getRegisterAuthCode')" type="button" ><fmt:message key="i18n.getVerificationCode" /></button>
					         			</div>
				         			</div>
								  </div>
								  <div class="form-actions" style="background-color:#FFFACD;">
									<button id="register_form_submit" type="button" class="btn btn-success" ><fmt:message key="i18n.lookAgreement"/></button>
								  </div>
								</form>
								<!-- SOCIAL REGISTER -->
								<div class="divide-20"></div>
								<div class="center">
									<strong></strong>
								</div>
								<div class="divide-20"></div>
								<!-- /SOCIAL REGISTER -->
								<div class="login-helpers">
									<a href="#" onclick="swapScreen('login');return false;"> 返回登录</a> <br>
								</div>
							</div>
						</div>
					</div>
				</div>
			</section>
			<div id="userAgreement" style="display: none;font-size: 14px;"><jsp:include page="userAgreement.jsp" /></div>
			<!--/REGISTER -->
			<!-- FORGOT PASSWORD -->
			<section id="forgot">
				<div class="container">
					<div class="row">
						<div class="col-md-4 col-md-offset-4">
							<div class="login-box-plain" style="background-color:#FFFACD;">
								<h2 class="bigintro"><fmt:message key="i18n.findPassword" /></h2>
								<div class="divide-40"></div>
								<form role="form" action="registerUser!getBack.action" method="post" class="login_form" id="my-form-forget">
								  <div class="form-group">
									<label for="exampleInputEmail1">登入账号：</label>
									<i class="fa fa-user"></i>
									<input type="text" name="registerUserDTO.loginName" id="forgetLoginName" class="form-control" placeholder="<fmt:message key="i18n.loginUserName" />">
								  </div>
								   <div class="form-group">
									<label for="exampleInputPassword1"><fmt:message key="i18n.loginPassword" />：</label>
									<i class="fa fa-lock"></i>
									<input type="password" class="form-control" placeholder="<fmt:message key="i18n.regInputPwd" />"
				name="registerUserDTO.password1" id="cp1_newPassword" >
								  </div>
								  <div class="form-group">
									<label for="exampleInputPassword1"><fmt:message key="i18n.cofimPassword" />：</label>
									<i class="fa fa-lock"></i>
									<input type="password" class="form-control" placeholder="<fmt:message key="i18n.regInputRepwd" />"
				id="cp1_repassword"  >
								  </div>
								  <div class="form-group">
									<label for="exampleInputPassword1"><fmt:message key="i18n.send2Password" />：</label>
									<i class="fa fa-lock"></i>
									<input type="password" class="form-control" placeholder="<fmt:message key="i18n.regInputPwd" />"
				name="registerUserDTO.password2" id="cp2_newPassword" />
								  </div>
								  <div class="form-group">
									<label for="exampleInputPassword1"><fmt:message key="i18n.cofimPassword" />：</label>
									<i class="fa fa-lock"></i>
									<input type="password" class="form-control" placeholder="<fmt:message key="i18n.regInputRepwd" />"
				id="cp2_repassword" >
								  </div>
								  <div class="form-group">
								  	<div class="row">
										<div class="col-xs-8">
										<label ><fmt:message key="i18n.mobileCode" />：</label>
										</div>
									</div>
									<div class="row">
										<div class="col-xs-7">
											<i class="fa fa-lock"></i>
											<input class="form-control" type="text" id="forgetRegisterAuthCode" name="registerUserDTO.authCode" placeholder="<fmt:message key="i18n.regInputVerificationCode" />" />
										</div>
										<div class="col-xs-5">
											<button id="getRegisterAuthCode" type="button" class="form-control" onclick="getVerificationCode('Mobile','FindPassword','#forgetLoginName','#getRegisterAuthCode',true)"><fmt:message key="i18n.getVerificationCode" /></button>
					         			</div>
				         			</div>
								  </div>
								  <div class="form-group"> 
									<div class="row">
										<div class="col-xs-8">
										<label ><fmt:message key="i18n.valicode" />：</label>
										</div>
									</div>
									<div class="row">
										<div class="col-xs-8">
											<i class="fa fa-lock"></i>
											<input class="form-control" id="forget_userLogin_validCode" name="code" type="text" placeholder="<fmt:message key="i18n.regInputVerificationCode" />" >
										</div>
										<div class="col-xs-4">
											<a href="javascript:refreshCheckCode('login_codeImg');"> <img id="login_codeImg" border=0 src="randomCode" /></a>
					         			</div>
				         			</div>
								  </div>
								  <div class="form-actions" style="background-color:#FFFACD;">
									<button type="button" class="btn btn-info" onclick="findPwd( )" ><fmt:message key="i18n.submitVil" /></button>
								  </div>
								</form>
								<div class="login-helpers">
									<a href="#" onclick="swapScreen('login');return false;">返回登录</a> <br>
								</div>
							</div>
						</div>
					</div>
				</div>
			</section>
			<!-- FORGOT PASSWORD -->
	</section>
	<!--/PAGE -->
	<!-- JAVASCRIPTS -->
	<!-- Placed at the end of the document so the pages load faster -->
	<!-- JQUERY UI-->
	<script src="${basePath}CloudFrame/js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
	<!-- BOOTSTRAP -->
	<script src="${basePath}CloudFrame/bootstrap-dist/js/bootstrap.min.js"></script>
	
	
	<!-- UNIFORM -->
	<script type="text/javascript" src="${basePath}CloudFrame/js/uniform/jquery.uniform.min.js"></script>
	<!-- CUSTOM SCRIPT -->
	<script src="${basePath}CloudFrame/js/script.js"></script>
	<script>
		jQuery(document).ready(function() {		
			App.setPage("login");  //Set current page
			App.init(); //Initialise plugins and elements
		});
	</script>
	<script type="text/javascript">
		function swapScreen(id) {
			jQuery('.visible').removeClass('visible animated fadeInUp');
			jQuery('#'+id).addClass('visible animated fadeInUp');
		}
	</script>
	<!-- /JAVASCRIPTS -->
	<script type="text/javascript">
	function findPwd(){
		if($('#forgetLoginName').val()=='' || $('#forgetLoginName').val()=='会员编号'){
			alert('请输入登入账号!');
			$('#forgetLoginName').focus();
			return false;
		}
		if($('#cp1_newPassword').val()=='' ){
			alert('新密码不能为空!'); $('#cp1_newPassword').focus();
			return false;
		}
		if($('#cp1_repassword').val() != $('#cp1_newPassword').val() ){
			alert('确认密码与新密码不一致'); $('#cp1_repassword').focus();
			return false;
		}
		if($('#cp2_newPassword').val()=='' ){
			alert('新密码不能为空!'); $('#cp2_newPassword').focus();
			return false;
		}
		if($('#cp2_repassword').val() != $('#cp2_newPassword').val() ){
			alert('确认密码与新密码不一致'); $('#cp2_repassword').focus();
			return false;
		}
		
		/* if($('#password').val()=='' || $('#password').val()=='密码'){
			alert('Please enter the password(请输入密码)!');
			$('#password').focus();
			return false;
		} */
		
		if( $('#forgetRegisterAuthCode').val()=='' || $('#forgetRegisterAuthCode').val()=='验证码'){
			alert('请输入验证码!');
			$('#forgetRegisterAuthCode').focus();
			return false;
		}
		if( $('#forget_userLogin_validCode').val()=='' || $('#forget_userLogin_validCode').val()=='验证码'){
			alert('请输入验证码!');
			$('#forget_userLogin_validCode').focus();
			return false;
		}
		
		
		
		var validCode = $('#forget_userLogin_validCode').val();
		$.get('getCode.jsp'+'?random='+Math.random()*10+1,function(res){
			 res=res.replace(/(^\s*)|(\s*$)/g, ""); 
			 if(validCode==res){
				$('#my-form-forget').submit();
			}else{
				alert('验证码不正确!');
			}
		});
		
		
	}
		/* $(function(){
			document.onkeydown = function(evt){
				var evt = window.event?window.event:evt;
				if(evt.keyCode==13){
					userLogin('yes');
				}
			}
			$('#loginName,#password').val('');
		}); */
		$(function (){
		    $('input[name="registerUserDTO.loginName"]').focus(function (){
		        if($.trim($(this).val()) == '用户名'){
		            $(this).val('');
		        }
		    }).blur(function (){
		        if($.trim($(this).val()) == ''){
		            //$(this).val('用户名');
		        }
		    });
		
		    $('input[name="registerUserDTO.password1"]').focus(function (){
		        if($.trim($(this).val()) == '密 码'){
		            $(this).val('');
		        }
		    }).blur(function (){
		        if($.trim($(this).val()) == ''){
		           //$(this).val('密 码');
		        }
		    });
		    
		    $('input[name="code"]').focus(function (){
		        if($.trim($(this).val()) == '验证码'){
		            $(this).val('');
		        }
		    }).blur(function (){
		        if($.trim($(this).val()) == ''){
		           // $(this).val('验证码');
		        }
		    });
		});
		
	</script>
</body>
</html>